<?php

ob_start();
include "globals.inc.php";

$con=mysql_connect($db_server,$db_username,$db_password);
//connection string

mysql_select_db($db_name,$con);
//select db

include "func.lib.php";

srand((double)microtime()*1000000);

$getGame = fetch("SELECT * FROM game_tables WHERE id = '$game'");
$game = $getGame[id];
$gameName = "<a href=index.php?game=$getGame[id] class=bottom>$getGame[game_name]</a>";

if ($getGame[use_logo] == "1")
{
	$gameName = "<a href=$base_url/index.php?game=$getGame[id]><img src=$base_url/images/user_images/opg_$game/logo.gif></a>";
}
$gameName2 = "$getGame[game_name]";
$pointVar = "$getGame[point_var]";
$pointsVar = "$getGame[point_var]";

if (!$pointVar) { $pointVar = "$defaultPointsVariable"; }

$userCookie = "username_$game";
$passCookie = "password_$game";

$getInfo = fetch("SELECT * FROM members2 WHERE username = '$HTTP_COOKIE_VARS[$userCookie]' AND password = '$HTTP_COOKIE_VARS[$passCookie]' AND game = '$game'");
$getInfo2 = fetch("SELECT * FROM members_profiles2 WHERE username = '$getInfo[username]' AND game = '$game'");

$username = $getInfo[username];
$display_name = $getInfo[display_name];
$userid = $getInfo[id];
$points = $getInfo[points];
$rank = $getInfo[rank];
$hungerLevel = $getInfo[hunger_level];

if (!$username)     { $username = "<i>Not logged in.</i>"; }
if (!$display_name) { $display_name = "<i>Not logged in.</i>"; }
if (!$points)       { $points = "0"; }

if ($getInfo[hunger_level] > 10) { mysql_query("UPDATE members SET hunger_level = 10 WHERE id = '$userid' AND game = '$game'"); $hungerLevel = 10;}

if ($getInfo[hunger_level] < 0) { mysql_query("UPDATE members SET hunger_level = 0 WHERE id = '$userid' AND game = '$game'");  $hungerLevel = 0; }

$hungerLevel = $hungerArray[$hungerLevel];

if (!$rank_check) { $rank_check = 0; }
if (!$rank) { $rank = 0; }
if ($rank < $rank_check)
{
	die(header(error("$base_url/login.php?game=$game","$noAccessError")));
}

#############
######## Hits
mysql_query("UPDATE hits SET hits = hits + 1");

mysql_query("UPDATE game_tables SET hits=$getGame[hits]+1 WHERE id = '$game'");

$current_date = "$getGame[the_current_date]";
$zeroHits = "0";
if ($datestamp != "$current_date")
{
	mysql_query("UPDATE game_tables SET daily_page_views=0 WHERE the_current_date != '$datestamp'") or die ("Database error: ".mysql_error());
	mysql_query("UPDATE game_tables SET the_current_date = '$datestamp' WHERE the_current_date != '$datestamp'") or die ("Database error: ".mysql_error());
	$getGame[daily_page_views] = 0;
}

mysql_query("UPDATE game_tables SET daily_page_views = daily_page_views + 1 WHERE id = '$game'");

#############

?>
